package com.speedycoders.recruitment.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.speedycoders.recruitment.model.Person;

@Service
public class PersonServiceImpl implements PersonService {

    @PersistenceContext
    private EntityManager em;

    public PersonServiceImpl() {
        // TODO Auto-generated constructor stub
    }

    @Override
    @Transactional
    public void persist(Person person) {
        //em.merge(person);
        em.persist(person);
    }

    public List<Person> readAll() {
        Query query = em.createQuery("from Person p order by p.id desc");

        query.setMaxResults(100);
        return query.getResultList();
    }
}
